/**
 * @author wei kunJie
 * @date 2024/3/13 16:10:29
 */
import androidx.compose.foundation.*
import androidx.compose.foundation.ContextMenuArea
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.text.TextContextMenu
import androidx.compose.foundation.text.TextContextMenu.TextManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.platform.LocalLocalization


@ExperimentalFoundationApi
val CustomLocalTextContextMenu:
        ProvidableCompositionLocal<CustomTextContextMenu> = staticCompositionLocalOf { CustomTextContextMenu }

@OptIn(ExperimentalFoundationApi::class)
object CustomTextContextMenu : TextContextMenu {
    @Composable
    override fun Area(textManager: TextManager, state: ContextMenuState, content: @Composable () -> Unit) {
        val items = {
            listOfNotNull(
                textManager.cut?.let {
                    ContextMenuItem("剪切", it)
                },
                textManager.copy?.let {
                    if (textManager.selectedText.isEmpty()) null
                    else ContextMenuItem("复制", it)
//                    ContextMenuItem("复制", it)
                },
                textManager.paste?.let {
                    ContextMenuItem("粘贴", it)
                },
                textManager.selectAll?.let {
                    ContextMenuItem("全选", it)
                },
            )
        }

        ContextMenuArea(items, state, content = content)
    }
}
